package cn.net.csit.platform_cloud.basicmodel.service.impl;

import cn.net.csit.platform_cloud.basicmodel.domain.BasicPropertyGroupRelationDomain;
import cn.net.csit.platform_cloud.basicmodel.domain.BasicPropertyGroupRelationDomainExample;
import cn.net.csit.platform_cloud.basicmodel.mapper.BasicPropertyGroupRelationDomainMapper;
import cn.net.csit.platform_cloud.basicmodel.service.IBackupDataService;
import cn.net.csit.platform_cloud.basicmodel.service.IBasicPropertyGroupRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @ClassName:
 * @Author:yanwenjuan
 * @Date:2019/4/810:03
 * @Description:
 */
@Service
public class BasicPropertyGroupRelationServiceImpl implements IBasicPropertyGroupRelationService {
    @Autowired
    private BasicPropertyGroupRelationDomainMapper mapper;
    @Autowired
    IBackupDataService backupDataService;

    @Override
    public int insert(BasicPropertyGroupRelationDomain record) {
        return mapper.insert(record);
    }

    @Override
    public int insertSelective(BasicPropertyGroupRelationDomain record) {
        return mapper.insertSelective(record);
    }



    @Override
    public BasicPropertyGroupRelationDomain selectByPrimaryKey(String uuid) {
        return mapper.selectByPrimaryKey(uuid);
    }

    @Override
    public List<Map<String, String>> deleteRelationByPK(Map<String, String> map) {
        List<Map<String,String>> result = new ArrayList<>();
        String where = " where 1=1";
        if(null != map & null !=map.get("prop_group_uuid")){
            where = where + "and bpg_r.prop_group_uuid='"+map.get("prop_group_uuid")+"'";
        }
        StringBuilder sb = new StringBuilder();
        sb.append(" DELETE FROM basic_property_group_relation bpg_r");
        sb.append(" "+where);
        result = backupDataService.customQueryItem(sb);
        return result;
    }

    @Override
    public List<Map<String, String>> deleteRelation(Map<String, String> map) {
        List<Map<String, String>> result=new ArrayList<>();
        String where=" where  1=1 ";
        if(null!=map&null!=map.get("prop_uuid")){
            where =where+" and prop_uuid='"+map.get("prop_uuid")+"'";
        }
        if(null != map & null!=map.get("prop_group_uuid")){
            where = where+" and prop_group_uuid='"+map.get("prop_group_uuid")+"'";
        }
        StringBuilder sb = new StringBuilder();
        sb.append( " DELETE FROM basic_property_group_relation ");
        sb.append(" "+where);
        result=backupDataService.customQueryItem(sb);
        return result;
    }

    @Override
    public List<Map<String, String>> selectRelation(Map<String, String> map) {
        List<Map<String,String>> result = new ArrayList<>();
        String where = " where 1 =1";
        if(null != map & null!= map.get("prop_group_uuid")){
            where = where + " and bpg_r.prop_group_uuid='"+map.get("prop_group_uuid")+"'";
        }
        if(null != map & null!= map.get("prop_uuid")){
            where = where + " and bpg_r.prop_uuid='"+map.get("prop_uuid")+"'";
        }
        StringBuilder sb = new StringBuilder();
        sb.append(" SELECT * FROM basic_property_group_relation bpg_r ");
        sb.append(" "+where+"");
        result= backupDataService.customQueryItem(sb);
        return result;
    }
}
